﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace EthnicEdu.Pages
{
    public partial class VerifyPage : PhoneApplicationPage
    {
        Service.IeThicEducationServiceClient service = new Service.IeThicEducationServiceClient();
        public VerifyPage()
        {
            InitializeComponent();
            service.GetAllWaitingQuestionCompleted += new EventHandler<Service.GetAllWaitingQuestionCompletedEventArgs>(service_GetAllWaitingQuestionCompleted);
            service.GetAllWaitingQuestionAsync();
            this.lstQuestion.SelectionChanged += new SelectionChangedEventHandler(lstQuestion_SelectionChanged);            
            service.GetAllAnswerByQuestionIdCompleted += new EventHandler<Service.GetAllAnswerByQuestionIdCompletedEventArgs>(service_GetAllAnswerByQuestionIdCompleted);
        }

        void service_GetAllAnswerByQuestionIdCompleted(object sender, Service.GetAllAnswerByQuestionIdCompletedEventArgs e)
        {
            try
            {
                if (e.Result.Count > 0)
                {
                    App.Question.Answers = e.Result;
                    this.NavigationService.Navigate(new Uri("/Pages/UploaderCreateQuestion.xaml", UriKind.Relative));
                }
            }
            catch 
            {
            }
        }

        void lstQuestion_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                App.Question = lstQuestion.SelectedItem as Service.Question;
                service.GetAllAnswerByQuestionIdAsync(App.Question.QuestionId);
                service.SetQuestionVerifyingAsync(App.Question.QuestionId);
            }
            catch 
            {
            }
        }

        void service_GetAllWaitingQuestionCompleted(object sender, Service.GetAllWaitingQuestionCompletedEventArgs e)
        {
            this.lstQuestion.ItemsSource = e.Result;   
        }
    }
}